home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4311 < prev    next >
Encoding:
Text File  |  1996-08-06  |  5.3 KB  |  100 lines

  1. Newsgroups: comp.lang.c++
  2. Path: tank.news.pipex.net!pipex!swrinde!gatech!psinntp!psinntp!psinntp!psinntp!bbnews1!trsvr!news
  3. From: bmr1@trpo4.tr.unisys.com (Benjamin Romer)
  4. Subject: Re: C, C++, or both..??
  5. Sender: news@tr.unisys.com (cnews news id.)
  6. Message-ID: <DLyBD0.1nM@tr.unisys.com>
  7. Date: Mon, 29 Jan 1996 16:34:12 GMT
  8. X-Nntp-Posting-Host: bmr1.tr.unisys.com
  9. References: <4ehif2$ljf@news.iconn.net>
  10. Organization: Unisys Corporation
  11. X-Newsreader: WinVN NT 0.92.6
  12.  
  13. In article <4ehif2$ljf@news.iconn.net>, thecrow@iconn.net (The Crow) says:
  14. >
  15. >I am 17 years old, I have a rudimentary understanding of both C and C++ at this 
  16. >point.(I know Pascal well) I want to really delve into something at this point. 
  17. >My eventual goal is to either start my own software company, or work for one as 
  18. >a programmer. Should I concentrate only on C++ for now, only C for now, or 
  19. >both? Or does it not really matter? I have read up on C++ and I really don't 
  20. >see much benefit from it. People have kept applications in order (mostly) for 
  21. >years without 'object oriented' programming...and C seems to be faster and much 
  22. >less of a pain.
  23.  
  24. C++ has *a lot* on "good old C", one aspect being that it is Good Old C, but 
  25. with a whole bunch of useful extensions. Although from a rudimentary standpoint,
  26. it may seem like there's little use for OOP, once you begin to realize some of the
  27. advantages that it gives, you'll wonder how you got along without them. For instance,
  28. writing an application for Windows in straight C requires you to do a lot of low and 
  29. mid-level programming, everything from interpreting the message to resize a window
  30. to sending a keyboard keypress to the right place. In a higher-level language like
  31. C++, you can write code to do these things _once_, then reuse the code for
  32. multiple projects. This allows the programmer to concentrate on _solving_the_problem_
  33. rather than dealing with system architecture.  Several premade libraries of code exist
  34. for just this purpose; I can think of two examples, Borland's OWL system, and the 
  35. Microsoft MFC system, that you could look into for a better idea of what I mean.
  36.  
  37. Another benefit can be seen when you begin to work in large groups on a project.
  38. In C, when two people would have to work together, they'd have to agree on a specific
  39. way to name every function and structure to prevent them from redefining another's
  40. code. With C++, The programmers can each be handed a design specification by
  41. the project leader, and they can use each other's objects without having to know 
  42. specifics. For instance, suppose a colleague and I are writing a program, and we
  43. need to implement both a tree and a linked list. in straight C, we'd have to define 
  44. TreeGetParent() and ListGetParent(), while in C++, we can both use GetParent() and
  45. let the compiler worry about which one to use. Although this example is trivial,
  46. I can easily imagine cases in which the same _semantic_ action must be applied
  47. to many different data structures, making calling the correct function much harder.
  48.  
  49. This leads me to a third point. There are a few things that you can do with C++ that
  50. you just cannot match with straight C. Using C++ inheritance, we can define a set
  51. of things, say, cars, which may all work in different ways, but are all basically the 
  52. same. I can make a Car class in C++, then derive DieselCar and ElectricCar from
  53. that class. Then, suppose I have a Race() function [for a game, perhaps!] to which
  54. I get a pointer to a Car:
  55.  
  56. void Race(Car *move)
  57. {
  58.     move->Accelerate();
  59. }
  60.  
  61. Not only do I not need to know which kind of Car it is, electric or diesel, but I also
  62. don't need to wonder what is the proper function to call! In straight C, you'd need
  63. the type of car as well as a switch statement, which could get *UGLY* if there's
  64. thirty or fourty types of cars.
  65.  
  66. >I have a few programs in mind were object orientation would be a more natural 
  67. >way of going about the program (evolution similuations) but a lot of programs 
  68. >don't really benefit from it at all.  The biggest improvements in C++ that I 
  69. >can see at this point are COUT/CIN, the comments, and NEW and DELETE...the rest 
  70. >just seems to make me type and think more.  Is it because I am just not used to 
  71. >the idea yet or is it really more complicated? The thing I hate most is the way 
  72. >member functions have to be outside of their class, totally counter intuitive 
  73. >and makes things very hard to follow. 
  74.  
  75. Actually, you can define the functions inline. Usually it is not done so that the
  76. interface to the code can be examined without having to read the implementation.
  77. This is another basis of OOP: the programmer, given an interface to the object,
  78. shouldn't have to know how it works "on the inside". Suppose you've got a digital
  79. watch; there are buttons for displaying the date, setting the alarm, etc. Do you
  80. need to know how the internal circuitry works to press the buttons? 
  81.  
  82. I'd suggest you get a good book on OOP. Try "Developing C++ Software" by
  83. Russel Winder, published by Wiley Professional Computing. It should fill out
  84. some of the holes in your experiences with C++, and answer some of the
  85. questions you have about using C++ effectively. If you'd like to contact me, 
  86. send mail to bmr1@trpo4.tr.unisys.com, or preferrably avenger@trend1.com.
  87.  
  88. Ben Romer
  89. Software Engineer
  90. Unisys Corporation
  91.  
  92. #include <stddisclaim.txt>
  93.  
  94.  
  95.  
  96. >The Crow - thecrow@iconn.net
  97. >"It can't rain all the time"
  98. >-Kryptology
  99. >
  100.